﻿using System;
using System.Collections;
using System.Collections.Generic;
using TrueSync;
using Network;
[System.Serializable]
public class StandHitState :StateBase 
{
    LogicMoveComponent mMoveComponent;

    public override StateEnum StateName
    {
        get
        {
            return StateEnum.StandHit; 
        }
    }

    public override bool IsFinished()
    {
        return !mMoveComponent.IsHittingBack;
    }

    public override void Enter(LogicEntity lEntity, StateBase lastState, object[] stateParams)
    {
        base.Enter(lEntity, lastState, stateParams);
        FP xTranslateLength = (FP)stateParams[0];
        FP xTranslateSpeed = (FP)stateParams[1];
        mMoveComponent = mLEntity.GetLogicComponent<LogicMoveComponent>();
        mMoveComponent.Hitback(xTranslateLength, -xTranslateSpeed * mMoveComponent.FaceDirection);
    }

    public override void Excute(FP deltaTime)
    {
        if (statusComponent.HP <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dead);
            return;
        }

        if (statusComponent.Dizzy <= 0)
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Dizzy);
            return;
        }

        if (IsFinished())
        {
            mLEntity.GetLogicComponent<LogicStateMachineComponent>().ChangeState(StateEnum.Stand);
        }
    }

    public override void Exit()
    {
        mMoveComponent.HitbackFinish();
        mMoveComponent = null;
        base.Exit();
    }

    public override void OnStimulate(Stimulate stimulate)
    {
        LogicStateMachineComponent stateMachineComponent = mLEntity.GetLogicComponent<LogicStateMachineComponent>();
        switch (stimulate.StimulateType)
        {
            case StimulateTypeEnum.HitFloatStimulate:
                HitFloatStimulate hitfloatStimulate = (HitFloatStimulate)stimulate;
                stateMachineComponent.ChangeState(StateEnum.FloatHit, hitfloatStimulate.XMoveLength, hitfloatStimulate.XMoveSpeed, hitfloatStimulate.YHeight);
                break;
            case StimulateTypeEnum.HitBackStimulate:
                HitBackStimulate hitbackStimulate = (HitBackStimulate)stimulate;
                stateMachineComponent.ChangeState(StateEnum.StandHit, hitbackStimulate.XMoveLength, hitbackStimulate.XMoveSpeed);
                break;
            case StimulateTypeEnum.HitFlyStimulate:
                HitFlyStimulate hitflyStimulate = (HitFlyStimulate)stimulate;
                stateMachineComponent.ChangeState(StateEnum.HitFly, hitflyStimulate.XMoveLength, hitflyStimulate.XMoveSpeed);
                break;
            case StimulateTypeEnum.ThrowStimulate:
                stateMachineComponent.ChangeState(StateEnum.ThrowHit);
                break;
        }
    }
}
